import axios from "axios";

export default {
  addGoods(goods) {
    return axios
      .post("/shopGoods/addGoods", goods)

      .then(function (response) {
        console.log(response);
        return response.data;
      })
      .catch(function (error) {
        console.log(error);
      });
  },
  get({ curPage, eachPage }) {
    return axios.get('/shopGoods', {

      params: {
        curPage,
        eachPage
      }
    })
      .then(function (response) {

        return response.data
      });
  },
  //更新
  updataGoods(goods) {


    return axios.patch('/shopGoods/updata', goods)
      .then(function (response) {

        return response.data

      })
      .catch(function (error) {
        console.log(error);
      });
  },

  // 删除
  delGoods(_id) {

    return axios.delete('/shopGoods/delgoods',
      {
        params: {
          _id
        }
      }
    )
      .then(function (response) {

        return response.data
      })
      .catch(function (error) {
        console.log(error);
      });
  },
  //查询
  serchGoods(serName) {

    return axios.get('/shopGoods/serchgoods', {
      params: {
        serName
      }
    })
      .then(function (response) {

        return response.data
      })
  },
  //删除图片
  delImg(_id, images) {
    console.log({ _id, images });
    return axios.delete('resource/goods/imgs',
      {
        params: {
          _id,
          images
        }
      }
    )
      .then(function (response) {

        return response.data
      })
      .catch(function (error) {
        console.log(error);
      });
  },
  //修改图片
  updataImg({_id,images}) {
    return axios.patch('/shopGoods/updataImg',
      {
        params: {
          _id, 
          images
        }
      }
    )
      .then(function (response) {

        return response.data

      })
      .catch(function (error) {
        console.log(error);
      });
  },

};
